package ru.nsu.fit.iconveyor.conveyor.channel;

import ru.nsu.fit.iconveyor.conveyor.Element;
import ru.nsu.fit.iconveyor.engine.exception.ChannelOverflowException;

/**
 * Channel which connects 2 nodes, collect data produced by input node and provides it to output node
 * @param <T>
 */
public abstract class Channel <T> extends Element {
    protected Channel(String id) {
        super(id);
    }

    /**
     * Adds data to channel.
     * @param data
     * @throws ChannelOverflowException in case of channel overflowing
     */
    public abstract void add(T data) throws ChannelOverflowException;

    /**
     * Retrieves and removes element which was added last, or returns null if this channel is empty.
     * @return element which was added last, or null if this channel is empty
     */
    public abstract T poll();

    /**
     * Retrieves element which was added last, or returns null if this channel is empty.
     * @return element which was added last, or null if this channel is empty
     */
    public abstract T peek();

    /**
     * Indicates if channel is empty.
     * @return
     */
    public abstract boolean isEmpty();
}
